package com.newear.base.ui;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ListView;

/**
 * 普通的ListView类
 * @author josan_tang
 *@since 20160717
 */
public class MyListView extends ListView {
	private static final String TAG = "MyListView";
	
	private boolean isInScrollView = false;	//是否在ScrollView中
	private View footView;	//ListView的最后一行
	
	public MyListView(Context context) {
		super(context);
		// TODO Auto-generated constructor stub
	}
	
	public MyListView(Context context, AttributeSet attrs) {
		super(context, attrs);
		// TODO Auto-generated constructor stub
	}

	public MyListView(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		// TODO Auto-generated constructor stub
	}
	
	@Override
	public void addFooterView(View v) {
		// TODO Auto-generated method stub
		removeFooterView(footView);
		super.addFooterView(v);
		footView = v;
	}
	
	public boolean removeFooterView(){
		return removeFooterView(footView);
	}
	
	public View getFootView(){
		return footView;
	}
	
	@Override
	public boolean removeFooterView(View v) {
		// TODO Auto-generated method stub
		if(super.removeFooterView(v)){
			footView = null;
			return true;
		}
		return false;
	}
	
	public void setInScrollView(boolean isInScrollView){
		this.isInScrollView = isInScrollView; 
	}
	
	public boolean getInScrollView(){
		return isInScrollView;
	}

	@Override
	protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
		// TODO Auto-generated method stub
		if(isInScrollView){
			int expanSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >>2, MeasureSpec.AT_MOST);
			super.onMeasure(widthMeasureSpec, expanSpec);
		}else{
			super.onMeasure(widthMeasureSpec, heightMeasureSpec);
		}
		
	}

	@Override
	protected void onLayout(boolean changed, int l, int t, int r, int b) {
		super.onLayout(changed, l, t, r, b);
	}
}
